package com.ch999.detect.View.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ch999.detect.R;
import com.ch999.detect.View.dialog.SelectParmsDialog;
import com.ch999.detect.mode.bean.GoodsBjgz;
import com.ch999.detect.utils.CommUtils;
import com.ch999.util.StatusBarUtil;
import com.github.mzule.activityrouter.annotation.Router;
import com.scorpio.mylib.ottoBusProvider.BusEvent;
import com.scorpio.mylib.ottoBusProvider.BusProvider;

import java.util.List;

/**
 * Created by Administrator on 2016/12/13 0013.
 */

@Router({"screenView"})
public class ScreenActivityApp extends AppCompatActivity implements View.OnClickListener {

    RelativeLayout activityMain;
    TextView tvColorText;
    RelativeLayout rlColor;


    private int posation;

    int[] colors = new int[]{
            R.color.white,
            R.color.black,
            R.color.blue,
    };

    int[] texts = new int[]{

            R.string.screen_text_0,
            R.string.screen_text_1,
            R.string.screen_text_2,

    };

    public int num = 0;
    private SelectParmsDialog mScreenSelectDialog;


    //    public Handler handler = new Handler() {
//        @Override
//        public void handleMessage(Message msg) {
//            super.handleMessage(msg);
//            if (msg.what == 0) {
//
//
//                finish();
//
//            } else if (msg.what == 1) {
////                mScreenSelectDialog.showDialog(mValues, "屏幕显示正常吗？");
//                // isCall = false;
//            }
//        }
//    };
    private List<GoodsBjgz.AttrBean> mAttrBeen;
//    private List<GoodsBjgz.AttrBean.ValuesBean> mValues;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.screen_layout);
        initView();
        findView();
        StatusBarUtil.setColor(this, this.getResources().getColor(com.ch999.baseres.R.color.es_w), 0);
//        StatusBarUtil.setLightMode(this);
//        StatusBarUtil.setTransparent(this);
//        StatusBarUtil.setLightMode(this);
        onChangeColorText();
    }
//
//    @Override
//    public int getLayoutId() {
//        return R.layout.screen_layout;
//    }

    public void initView() {

        mAttrBeen = CommUtils.mPhoneAttr;


        Intent intent = getIntent();
        num = 0;
//        mScreenSelectDialog = new SelectParmsDialog(mContext, new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                int tag = (int) view.getTag();
//                wifUsable(tag);
//            }
//        });

//        posation = intent.getIntExtra(MainActivityApp.EXTRA_POSATION, -1);

//        mValues = mAttrBeen.get(NewDetectActivity.curIndex).getValues();

//        setTitel(tvScreen);


    }


    public void setTitel(TextView view) {
        String titleName = view.getText().toString();
        titleName = titleName + (posation + 1) + "/" + CommUtils.mAttrSize;
        view.setText(titleName);
    }

    public void onChangeColorText() {


        if (num > 2) {

            //检测完成
            BusEvent event = new BusEvent();
            event.setAction(NewDetectActivity.BUSACTION_SCREENDETECT_SUCCESS);
            BusProvider.getInstance().post(event);
            finish();
//            handler.sendEmptyMessageDelayed(1, 200);
            return;
        }

//        rlColor.setVisibility(View.VISIBLE);

        tvColorText.setText(texts[num]);
        rlColor.setBackgroundResource(colors[num]);

        StatusBarUtil.setColor(this, getResources().getColor(colors[num]), 0);


        num++;
    }

//    private void wifUsable(int itemPosation) {
//
//
//        if (mScreenSelectDialog != null) {
//            mScreenSelectDialog.dismiss();
//        }
//
//        SharePrefUtil.getInstance(mContext).putInt(SpType.KEY_POSATION, posation);
//
//        EventBus.getDefault().post(new FacationMode(posation, itemPosation));
//
////        handler.sendEmptyMessageDelayed(0, 1000);
//
//        isStartContineDetect();
//    }


    private void isStartContineDetect() {
        Intent intent = getIntent();
        boolean isAction = intent.getBooleanExtra(MainActivityApp.EXTRA_ACTION, false);
        if (isAction) {

            Intent autoIntent = CommUtils.getInstance().getAutoDetectActivityIntent(this, posation + 1);

            if (autoIntent != null) {
                startActivity(autoIntent);
            }
        }
    }

    public void onClick(View view) {
        int i = view.getId();
//        else if (i == R.id.ll_check) {
//            num = 0;
//            onChangeColorText();
//
//        }
        if (i == R.id.rl_color) {
            onChangeColorText();

        }
//        else if (i == R.id.img_menu) {
//            finish();
//
//        } else if (i == R.id.img_back) {
//            finish();
//
//        }
    }

    public void findView() {

        activityMain = (RelativeLayout) findViewById(R.id.activity_main);
        tvColorText = (TextView) findViewById(R.id.tv_color_text);
        rlColor = (RelativeLayout) findViewById(R.id.rl_color);

    }
}
